package com.bright.multiphoto;

import java.util.ArrayList;

import com.project.weimi.R;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

public class ViewPagerPhotoActivity extends AlbumBaseActivity {

	ViewPager viewPager = null;
	ArrayList<String> selectedItems = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_viewpager);
		selectedItems = new ArrayList<String>();

		Intent intent = getIntent();
		Bundle bundle = intent.getBundleExtra("bundle");
		selectedItems = bundle.getStringArrayList("selectedItems");

		Log.e(ViewPagerPhotoActivity.class.getSimpleName(), selectedItems.toString());

		viewPager = (ViewPager) this.findViewById(R.id.viewpager);

		ViewPagerAdapter adapter = new ViewPagerAdapter();
		viewPager.setAdapter(adapter);
	}

	private class ViewPagerAdapter extends PagerAdapter {

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return selectedItems.size();
		}

		@Override
		public boolean isViewFromObject(View arg0, Object arg1) {
			// TODO Auto-generated method stub
			return arg0 == arg1;
		}

		@Override
		public Object instantiateItem(ViewGroup container, int position) {
			// TODO Auto-generated method stub
			ImageView imageView = new ImageView(getApplicationContext());

			imageLoader.displayImage(selectedItems.get(position), imageView, options);

			container.removeView(imageView);
			container.addView(imageView);

			return imageView;
		}

		@Override
		public void destroyItem(ViewGroup container, int position, Object object) {
			// TODO Auto-generated method stub
			// super.destroyItem(container, position, object);
			ImageView imageView = new ImageView(getApplicationContext());

			imageLoader.displayImage(selectedItems.get(position), imageView, options);

			container.removeView(imageView);
		}

	}

	@Override
	protected void onStop() {
		imageLoader.stop();
		super.onStop();
	}
}
